//https://leetcode.cn/problems/design-circular-queue/submissions/555452523/
class MyCircularQueue {
    int[] queue;
    int front;
    int rear;

    public MyCircularQueue(int k) {
        queue = new int[k+1];
    }
    
    public boolean enQueue(int value) {
        if (isFull()) return false;
        queue[rear] = value;
        rear = (rear+1)% queue.length;
        return true;
    }
    
    public boolean deQueue() {
        if (isEmpty()) return false;
        front = (front+1)% queue.length;
        return true;
    }
    
    public int Front() {
        if (isEmpty()) return -1;
        return queue[front];
    }
    
    public int Rear() {
        if (isEmpty()) return -1;
        if (rear != 0) {
            return queue[rear-1];
        }
        int rearN = queue.length-1;
        return queue[rearN];
    }
    
    public boolean isEmpty() {
        return front == rear;
    }
    
    public boolean isFull() {
        if ((rear+1)% queue.length == front)
            return true;
        return false;
    }
}